import { ResultType } from '@/mock/modules/Login'
import profile from '@/assets/images/R-C.gif'
export interface loginTypeStore {
  user: ResultType
  menu_open: boolean
  user_img: string
}
export const useLoginStore = defineStore('login', {
  // other options...
  state: (): loginTypeStore => {
    return {
      user: {
        username: '',
        token: null,
        user_id: 0
      },
      user_img: profile,
      menu_open: true
    }
  },
  actions: {
    SETTOKEN(val: ResultType) {
      this.user = val
    },
    SETMENUOPEN() {
      this.menu_open = !this.menu_open
    },
    SETWINDOWSWIDTH(open_close: boolean) {
      this.menu_open = open_close
    },
    // 退出重置
    LOGOUT() {
      sessionStorage.clear()
      window.location.reload()
    }
  },
  getters: {},
  persist: {
    // 修改存储中使用的键名称，默认为当前 Store的 id
    key: 'Login',
    // 修改为 sessionStorage，默认为 localStorage
    storage: window.sessionStorage,
    // 部分持久化状态的点符号路径数组，[]意味着没有状态被持久化(默认为undefined，持久化整个状态)
    paths: ['user', 'menu_open']
  }
})
